//
//  GetData.m
//  Moment
//
//  Created by dllo on 15/12/21.
//  Copyright © 2015年 谭泽源. All rights reserved.
//

#import "GetData.h"
#import <AFNetworking.h>

@implementation GetData

+ (void)getDataWithURL:(NSString *)url block:(GetDataBlock)block
{
    //最好编码一下
    NSString *urlEncode = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    

        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
        [manager GET:urlEncode parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            block(responseObject);
    
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            
            NSLog(@"错误信息%@", error);
        }];

}


+ (void)getDataWithURL:(NSString *)url postDic:(NSDictionary *)dic block:(GetDataBlock)block
{
    
    AFHTTPSessionManager *netManager = [AFHTTPSessionManager manager];
    netManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    
    [netManager POST:url parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        block(responseObject);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"错误信息%@", error);

    }];
    
    
}



@end
